#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <setjmp.h>

#include "progress_bar.h"

#define UNUSED(x)  ((void)x)

static jmp_buf buf;

static void deal_ctrl_c(int sig);

int main(int argc, char *argv[])
{
    int ret;
    struct progress_bar progress_data;
    func_t draw[MAX_FUNC];

    UNUSED(argc);
    UNUSED(argv);

    signal(SIGINT, deal_ctrl_c);

    progress_bar_init(&progress_data, draw);
    set_terminal_param(argc, argv, &progress_data);

    ret = setjmp(buf);

    if (ret != 1) {
        progress_bar_run(&progress_data, draw);
    } else {
        progress_bar_destroy();
    }

    return 0;
}

static void deal_ctrl_c(int sig)
{
    longjmp(buf, 1);    
}
